import { createWebHashHistory, createRouter } from 'vue-router';

// 公共路由
export const constantRoutes = [
  {
    path: '/',
    redirect: '/cesiumJS', // 根路径直接重定向到 /three
    meta: { title: '3D模型', icon: 'international', affix: false, breadcrumb: false }
  },
  {
    path: '/cesiumJS',
    component: () => import('@/views/cesiumJS/cesiumJS'),
    name: 'CesiumJS',
    meta: { title: '地理空间数据可视化', icon: 'international', affix: false, breadcrumb: false }
  },
  {
    path: '/video_cai',
    component: () => import('@/views/video_cai/video_cai'),
    name: 'Video_Cai',
    meta: { title: '视频分析平台', icon: 'international', affix: false, breadcrumb: false }
  },
  /* {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  }, */
  /* {
    path: '',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: () => import('@/views/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  }, */
  {
    path: '/GIS',
    redirect: '/GIS/map',
    hidden: true,
    meta: { title: '地图', icon: 'international' },
    children: [
      {
        path: 'map',
        component: () => import('@/views/map/GIS/map'),
        name: 'GISMap',
        meta: { title: '地图', icon: 'international', affix: false, breadcrumb: false }
      }
    ]
  },
  {
    path: '/three',
    redirect: '/three/three',
    hidden: true,
    meta: { title: '3D模型', icon: 'international' },
    children: [
      {
        path: 'three',
        component: () => import('@/views/three/three'),
        name: 'threeDemo',
        meta: { title: '3D模型', icon: 'international', affix: false, breadcrumb: false }
      }
    ]
  },
  {
    path: '/mineCar',
    redirect: '/mineCar/mineCar',
    hidden: true,
    meta: { title: 'css矿车', icon: 'international' },
    children: [
      {
        path: 'mineCar',
        component: () => import('@/views/mineCar/mineCar'),
        name: 'MineCar',
        meta: { title: 'css矿车', icon: 'international', affix: false, breadcrumb: false }
      },
    ]
  },
  {
    path: '/svgdemo',
    redirect: '/svgdemo/svgdemo',
    hidden: true,
    meta: { title: 'svgdemo', icon: 'international' },
    children: [
      {
        path: 'svgdemo',
        component: () => import('@/views/svgdemo/svgdemo'),
        name: 'Svgdemo',
        meta: { title: 'svgdemo', icon: 'international', affix: false, breadcrumb: false }
      },
    ]
  },
]

const router = createRouter({
  history: createWebHashHistory(), // 使用 hash 模式
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
});

export default router;
